package tech.aistar.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.aistar.entity.Collections;
import tech.aistar.entity.trading.Goods;
import tech.aistar.mapper.CollectionsMapper;
import tech.aistar.service.ICollectionsService;
import tech.aistar.service.IGoodsService;

import java.util.ArrayList;
import java.util.List;
@Service
@Transactional
public class CollectionsServiceImpl implements ICollectionsService {
    @Autowired
    private CollectionsMapper collectionsMapper;
    @Autowired
    private IGoodsService goodsService;
    @Override
    public Integer findById(Integer id) {
        Integer count = collectionsMapper.findById(id);
        return count;
    }

    @Override
    public Goods findByGood(Integer kindId) {
        Goods g = goodsService.findById(kindId);
        return g;
    }

    //分页
    @Override
    public PageInfo<Collections> findByGood(Integer id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Collections> clist = collectionsMapper.findByGood(1);
        PageInfo<Collections> goodpage = new PageInfo<>(clist);
        return goodpage;
    }

    @Override
    public List<Collections> findByPost(Integer id) {
        List<Collections> posts = collectionsMapper.findByPost(id);
        return posts;
    }

    @Override
    public List<Collections> findByNews(Integer id) {
        List<Collections> news = collectionsMapper.findByNews(id);
        return news;
    }

    @Override
    public void delGoods(Integer id, Integer kindId) {
        collectionsMapper.delGoods(id,kindId);
    }

    @Override
    public void delPosts(Integer id, Integer kindId) {
        collectionsMapper.delPosts(id,kindId);
    }
}
